package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.bean.ProductExtractBean;
import com.yanchangapp.ui.view.PtExtractAtView;
import com.zxl.baselib.bean.response.BaseListResponse;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-08-07.
 * description: 品种提取的p层
 */
public class PtExtractAtPresenter extends BasePresenter<PtExtractAtView> {

    public PtExtractAtPresenter(BaseActivity context) {
        super(context);
    }


    public void queryProductList(String contactId){
        HeadApiRetrofit.getInstance().queryProductExtractList(contactId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseListResponse<ProductExtractBean>>() {
                    @Override
                    public void onNext(BaseListResponse<ProductExtractBean> productExtractBeanBaseListResponse) {
                        if (productExtractBeanBaseListResponse.getCode() == AppConstant.REQUEST_SUCCESS){

                            if (null != getView()){
                                getView().queryPtExtractSuccess(productExtractBeanBaseListResponse.getData());
                            }
                        }else {
                            if (null != getView()){
                                getView().queryPtExtractFailure(productExtractBeanBaseListResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (getView() != null){
                            getView().queryPtExtractFailure(exception.getErrorInfo());
                        }
                    }
                });
    }

}
